<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>希尔排序</title>
</head>
<body>
<h3>希尔排序</h3>
<script>
	function shellSort(arr) {
    var len = arr.length,
        temp,
        gap = 1;
    while(gap < len/3) {          //动态定义间隔序列
        gap =gap*3+1;
    }
    for (gap; gap > 0; gap = Math.floor(gap/3)) {
        for (var i = gap; i < len; i++) {
            temp = arr[i];
            for (var j = i-gap; j >= 0 && arr[j] > temp; j-=gap) {
                arr[j+gap] = arr[j];
            }
            arr[j+gap] = temp;
        }
    }
    return arr;
}
	console.log( shellSort([1,3,2,4,56,7,84,3,5]) )
</script>
</body>
</html>
